package com.example.dictdemo.common.enums;

import com.example.dictdemo.aspect.annotation.EnumDict;
import com.example.dictdemo.enhance.EnumDictMethodEnhance;
import com.example.dictdemo.model.vo.DictModel;

import java.util.ArrayList;
import java.util.List;

/**
 * 性别枚举
 *
 * @author dlp
 * @date 2024/08/20
 */
@EnumDict("sex")
public enum SexEnum implements EnumDictMethodEnhance {
  Male("Male", "男"),

  Female("Female", "女");


  SexEnum(String key, String title) {
    this.key = key;
    this.title = title;
  }

  private String key;

  private String title;


  public String getKey() {
    return key;
  }

  public String getTitle() {
    return title;
  }

  /**
   * 获取字典列表
   *
   * @return {@link List }<{@link DictModel }>
   */
  @Override
  public List<DictModel> getDictList() {
    List<DictModel> list = new ArrayList<>();
    for (SexEnum e : SexEnum.values()) {
      DictModel dictModel = new DictModel();
      dictModel.setValue(e.getKey());
      dictModel.setText(e.getTitle());
      list.add(dictModel);
    }
    return list;
  }

  /**
   * 有效
   *
   * @return boolean
   */
  @Override
  public boolean isValid(String key) {
    if (key==null){
      return false;
    }
    for (SexEnum sexEnum : SexEnum.values()) {
      if (sexEnum.getKey().equals(key)){
        return true;
      }
    }
    return false;
  }

}
